﻿#include "mainwindow.h"
#include "./ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    InitControls();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButtonEditText_clicked()
{
    QString strText = ui->lineEditText->text();
    ui->labelShow->setText( strText );
}


void MainWindow::on_fontComboBox_currentTextChanged(const QString &arg1)
{
    QFont txtFont( arg1, ui->spinBoxSize->value() );
    ui->labelShow->setFont( txtFont );
}


void MainWindow::on_spinBoxSize_valueChanged(int arg1)
{
    QFont txtFont(ui->fontComboBox->currentText(), arg1);
    ui->labelShow->setFont( txtFont );
}


void MainWindow::on_comboBoxFGColor_currentTextChanged(const QString &arg1)
{
    QString strFGColor = arg1; //前景色
    QString strBGColor = ui->comboBoxBGColor->currentText(); //背景色
    //样式表
    QString strCSS = QString("color: %1; background-color: %2;").arg( strFGColor, strBGColor );
    ui->labelShow->setStyleSheet( strCSS );
}


void MainWindow::on_comboBoxBGColor_currentTextChanged(const QString &arg1)
{
    QString strFGColor = ui->comboBoxFGColor->currentText();; //前景色
    QString strBGColor = arg1; //背景色
    //样式表
    QString strCSS = QString("color: %1; background-color: %2;").arg( strFGColor, strBGColor );
    ui->labelShow->setStyleSheet( strCSS );
}

void MainWindow::InitControls(void)
{
    //字号旋钮框的范围
    ui->spinBoxSize->setRange(4, 100);
    ui->spinBoxSize->setValue( 9 );
    //颜色组合框的设置
    //获取常见颜色
    QStringList colorNames = QColor::colorNames();
    //设置前景色组合框
    ui->comboBoxFGColor->addItems( colorNames );
    //默认前景色 黑色
    ui->comboBoxFGColor->setCurrentText( "black" );
    //设置背景色组合框
    ui->comboBoxBGColor->addItems( colorNames );
    //默认背景色，浅灰
    ui->comboBoxBGColor->setCurrentText( "lightgray" );

    //修改工具箱本身的样式表
    QString strCSS = "::tab{ background-color: magenta; }"
                     "QWidget#pageText{ background-color: green; }"
                     "QWidget#pageFont{ background-color: cyan; }"
                     "QWidget#pageColor{ background-color: yellow; }";
    ui->toolBox->setStyleSheet( strCSS );
}
